/**   
 * @Title: PageInfo.java 
 * CopyRight(c)2010-DMX 
 */
package com.dmx.fw.bean;


import java.util.List;

/** 
 * @Description: the bean to page
 * @author: system
 * @date: 2008
 * @version V1.0 
 * 
 */
public class PageInfo implements java.io.Serializable{
	
	/** 
	 * @Fields pageSize: 每页的记录数
	 */
    private int pageSize = 10;
    
    /** 
	 * @Fields currentPageNo: 当前页
	 */
    private int currentPageNo = 1;
    
    /** 
	 * @Fields beginResult: 开始记录数
	 */
    private int beginResult = 0;
    
    /** 
	 * @Fields totalResult: 总记录数
	 */
    private int totalResult = 0;
    
    /** 
	 * @Fields totalPage: 总页数
	 */
    private int totalPage = 0;
    
    /** 
	 * @Fields busiId: //只是为了修改QueryServiceImpl引起的并发性的BUG
	 */
    private String busiId;
    
    /** 
	 * @Fields pageSize: 每页的记录数
	 */
    private List searchResult = null;
    
    /** 
	 * <p>Description: default constructor</p> 
	 */
    public PageInfo() {
    }

    /** 
	 * <p>Description: initialize pageSize</p> 
	 * @param pageSize: 每页记录数
	 */
    public PageInfo(int pageSize) {
    	this.pageSize = pageSize;
    }
    
    /**
     * <p>Description: initialize currentPageNo,pageSize</p> 
     * @param currentPageNo: 当前页的页码
     * @param pageSize: 每页有多少行记录
     */
    public PageInfo(int currentPageNo, int pageSize) {
        this.currentPageNo = currentPageNo;
        this.pageSize = pageSize;
    }

    /** 
    * @Description: 计算总页数
    */
    private void countPages() {
        if (totalResult == 0) {
            totalPage = 1;
        } else {
            totalPage = (totalResult / pageSize); //总共几页
            if ((totalResult % pageSize) != 0)
                totalPage = totalPage + 1;
        }
    }

    /**
     * 获得当前页
     * @return int 当前页
     */
    public int getCurrentPageNo() {
        return currentPageNo;
    }

    /**
     * 获得每页的记录数
     * @return int
     */
    public int getPageSize() {
        return pageSize;
    }

    /**
     * 获得总记录数
     * @return int
     */
    public int getTotalResult() {
        return totalResult;
    }

    /**
     * 设置当前页
     * @param current int 当前页码
     */
    public void setCurrentPageNo(int current) {
        this.currentPageNo = current;
    }

    /**
     * 设置每页的记录数
     * @param i int 记录数
     */
    public void setPageSize(int i) {
        pageSize = i;
    }

    /**
     * 获得开始记录数
     * @return int 开始记录数
     */
    public int getBeginResult() {
        int currentPage = getCurrentPageNo();
        int totalPage = getTotalPage();
        if (currentPage > totalPage) { //如果大于总页
            currentPage = totalPage;
            setCurrentPageNo(currentPage);
        }

        int currentResult = 0;
        currentResult = (currentPage - 1) * pageSize;

        return currentResult;
    }

    /**
     * @param i
     */
    public void setBeginResult(int i) {
        beginResult = i;
    }

    /**
     * 获得总页数
     * @return int 总页数
     */
    public int getTotalPage() {
        return totalPage;
    }

    /**
     * 设置总页数
     * @param i int 总页数
     */
    public void setTotalPage(int i) {
        totalPage = i;
    }


    /**
     * @param totalResult
     *            The totalResult to set. 设置该分页信息总共有多少条记录
     */
    public void setTotalResult(int totalResult) {
        this.totalResult = totalResult;
        countPages();
    }

    /**
     * @return Returns the searchResult.
     */
    public List getSearchResult() {
        return searchResult;
    }

    /**
     * @param searchResult The searchResult to set.
     */
    public void setSearchResult(List searchResult) {
        this.searchResult = searchResult;
    }

	/**
	 * @return the busiId
	 */
	public String getBusiId() {
		return busiId;
	}

	/**
	 * @param busiId the busiId to set
	 */
	public void setBusiId(String busiId) {
		this.busiId = busiId;
	}



}
